package cug.hexy.springbatchrabbitmqdemo.job;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SimpleBatchJob {

    @Bean
    public Job simpleJob(JobBuilderFactory jobBuilderFactory, StepBuilderFactory stepBuilderFactory) {
        Step step = stepBuilderFactory.get("simpleStep")
                .tasklet((contribution, chunkContext) -> {
                    System.out.println("执行批处理任务，处理Task ID：" +
                            chunkContext.getStepContext().getJobParameters().get("taskId"));
                    return RepeatStatus.FINISHED;
                })
                .build();

        return jobBuilderFactory.get("simpleJob")
                .start(step)
                .build();
    }
}
